package com.xiaok.netty.server.components;

import io.netty.channel.Channel;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Classname ChannelRepository
 * @Description 工具类把客户端id作为key放入map中 把 channel放入对应value，相当于做一个绑定
 * @Date 2020/10/8 11:02
 * @Created by xiaok
 */
@Component("channelRepository")
public class ChannelRepository {

    private final static Map<String, Channel> channelCache = new ConcurrentHashMap<String,Channel>();

    public void put(String key ,Channel value){ channelCache.put(key,value);}

    public Channel get(String key) { return channelCache.get(key);}

    public void remove(String key) { channelCache.remove(key);}

    public int size(){ return channelCache.size();}
}
